package cn.qg.biz.service.qgtrade;
import cn.qg.beans.pojo.QgTrade;
import cn.qg.common.Constants;
import cn.qg.common.EmptyUtils;
import cn.qg.common.Page;
import cn.qg.mapper.qgtrade.QgTradeMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class QgTradeServiceImpl implements QgTradeService {

    @Resource
    private QgTradeMapper qgTradeMapper;

    @Override
    public QgTrade getQgTradeById(Long id)throws Exception{
        return qgTradeMapper.getQgTradeById(id);
    }

    @Override
    public List<QgTrade>	getQgTradeListByMap(Map<String,Object> param)throws Exception{
        return qgTradeMapper.getQgTradeListByMap(param);
    }

    @Override
    public Integer getQgTradeCountByMap(Map<String,Object> param)throws Exception{
        return qgTradeMapper.getQgTradeCountByMap(param);
    }

    @Override
    public Integer qgtxAddQgTrade(QgTrade qgTrade)throws Exception{
            qgTrade.setCreatedTime(new Date());
            return qgTradeMapper.insertQgTrade(qgTrade);
    }

    @Override
    public Integer qgtxModifyQgTrade(QgTrade qgTrade)throws Exception{
        qgTrade.setCreatedTime(new Date());
        return qgTradeMapper.updateQgTrade(qgTrade);
    }

    @Override
    public Integer qgtxDeleteQgTradeById(Long id)throws Exception{
        return qgTradeMapper.deleteQgTradeById(id);
    }

    @Override
    public Page<QgTrade> queryQgTradePageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = qgTradeMapper.getQgTradeCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<QgTrade> qgTradeList = qgTradeMapper.getQgTradeListByMap(param);
        page.setRows(qgTradeList);
        return page;
    }

}
